package com.dome.collection;


import com.dome.model.*;
import com.dome.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DemoCollection {
    @Autowired
    private RoleService roleService;
    @Autowired
    private ResourceService resourceService;
    @Autowired
    private ResourceAuthorityService resourceAuthorityService;
    @Autowired
    private MenuService menuService;

    @RequestMapping("/role")
    public String runRole() {
        roleService.deleteRoleWH(Lightapp.id);
//        List<Role> roleWH = roleService.getWH(Lightapp.id);
        List<Role> roleBJ = roleService.getBJ(Lightapp.id);
        roleService.insertRoleWH(roleBJ);
        return "角色同步成功";

    }

    @RequestMapping("/menu")
    public String runMenu() {
        //北京 108  武汉  104
        menuService.deleteMenuWH(Lightapp.id);
//        List<Menu> menuWH = menuService.getWH(Lightapp.id);
        List<Menu> menuBJ = menuService.getBJ(Lightapp.id);
        menuService.insertMenuWH(menuBJ);
        return "菜单同步成功";
    }

    @RequestMapping("/resource")
    public String runResource() {
        resourceService.deleteResourceWH(Lightapp.id);
        List<Resource> resoueceWH = resourceService.getWH(Lightapp.id);
        List<Resource> resoueceBJ = resourceService.getBJ(Lightapp.id);
        resourceService.insertResourceWH(resoueceBJ);
        resoueceWH = resourceService.getWH(Lightapp.id);
        return "资源同步成功";
    }

    @RequestMapping("/resourceAuth")
    public String runResourceAuth() {
        //查询武汉角色
        List<Role> roleWH = roleService.getWH(Lightapp.id);
        //查询北京角色
        List<Role> roleBJ = roleService.getBJ(Lightapp.id);
        //查询武汉角色权限资源
        List<ResourceAuthority> resourceAuthoritiesWH = resourceAuthorityService.getWH(roleWH);
        //查询北京角色权限资源
        List<ResourceAuthority> resourceAuthoritiesBJ = resourceAuthorityService.getBJ(roleBJ);

        //删除武汉角色权限资源
        resourceAuthorityService.deleteResourceAuthorityWH(roleWH);
        resourceAuthorityService.insertResourceAuthorityWH(resourceAuthoritiesBJ);
        resourceAuthoritiesWH = resourceAuthorityService.getWH(roleWH);
        return "角色资源同步成功";
    }
}
